﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Entity;
using Runda.EShop.Common.Utility;
using Runda.EShop.Bll;
using System.Data;

namespace Runda.EShop.SaaS.CustomerManage
{
    public partial class EnterpriseList : BasePage
    {
        public override string FunctionID
        {
            get
            {
                return "Func1010";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid(ConstHelper.PAGE_INIT_INDEX);
            }
        }

        private void BindGrid(int PageIndex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null;
            if (!string.IsNullOrEmpty(txtEntName.Text))
            {
                parm = new SqlDbParameter();
                parm.ColumnName = "[EntName]";
                parm.ColumnType = DbType.String;
                parm.ParameterName = "@EntName";
                parm.ParameterValue = txtEntName.Text;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                parms.Add(parm);
            }

            if (!string.IsNullOrEmpty(txtEntCode.Text))
            {
                parm = new SqlDbParameter();
                parm.ColumnName = "[EntCode]";
                parm.ColumnType = DbType.String;
                parm.ParameterName = "@EntCode";
                parm.ParameterValue = txtEntCode.Text;
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                parms.Add(parm);
            }

            int RecordCount = 0;
            List<BizEnterpriseEntity> list = new BizEnterpriseBll().GetAll<BizEnterpriseEntity>(parms, "EntCode DESC", AspNetPager1.PageSize, PageIndex, out RecordCount);

            gvCustomerList.DataSource = list;
            gvCustomerList.DataBind();

            AspNetPager1.RecordCount = RecordCount;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }

        protected void lnkbtnQuery_Click(object sender, EventArgs e)
        {
            BindGrid(ConstHelper.PAGE_INIT_INDEX);
        }

        protected void gvCustomerList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                BizEnterpriseEntity entity = e.Row.DataItem as BizEnterpriseEntity;
                Label Label1 = e.Row.FindControl("Label1") as Label;
                Label Label2 = e.Row.FindControl("Label2") as Label;
                Label Label3 = e.Row.FindControl("Label3") as Label;

                if (entity.BusinessLicenseDeadline == DateTime.MinValue)
                {
                    Label1.Text = string.Empty;
                }
                if (entity.ApparatusLicenseDeadline == DateTime.MinValue)
                {
                    Label2.Text = string.Empty;
                }
                if (entity.DrugLicenseDeadline == DateTime.MinValue)
                {
                    Label3.Text = string.Empty;
                }

            }
        }

    }
}